package com.qinhailin.portal.business.ctrl;

import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.jfinal.plugin.activerecord.Record;

import com.qinhailin.common.base.BaseController;
import com.qinhailin.common.util.IDPhoneValidator;
import com.qinhailin.common.vo.Grid;
import com.qinhailin.portal.business.model.ICustomerInfo;
import com.qinhailin.portal.business.service.ICustomerInfoService;
import org.codehaus.jackson.node.ObjectNode;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.client.RestTemplate;

/**
 *
 * @author qinhailin
 * @date 2024-12-12
 */

@Path("/portal/business/iCustomerInfo")
public class ICustomerInfoController extends BaseController {

    @Inject
    ICustomerInfoService service;

  	public void index(){
    	render("index.html");
  	}

//    public void list() {
//        Record record=getAllParamsToRecord();
//        int pageNumber=getParaToInt("pageNumber", 1);
//        int pageSize=getParaToInt("pageSize", 10);
//        Grid g=service.page(pageNumber, pageSize,record);
//        renderJson(g);
//	}
    public void list(){
        Record record = getAllParamsToRecord();
        record.remove("pageSize","pageNumber");
        renderJson(service.queryForList(getParaToInt("pageNumber",1), getParaToInt("pageSize",10),record));
    }



    public void add() {
    	render("add.html");
    }

    public void save() {
        ICustomerInfo entity=getBean(ICustomerInfo.class);
    	entity.setId(createUUID());
    	entity.save();
    	setAttr("iCustomerInfo", entity);
    	render("add.html");
    }

    public void edit() {
        setAttr("iCustomerInfo", service.findById(getPara(0)));
        render("edit.html");
    }

    public void update() throws Exception {
        ICustomerInfo entity=getBean(ICustomerInfo.class);
        entity.update();
        setAttr("iCustomerInfo", entity);
        render("edit.html");
    }

    public void delete() {
        service.deleteByIds(getIds());
        renderJson(suc());
    }


    public void modify() {
        ICustomerInfo entity=getBean(ICustomerInfo.class);
        entity.setDevideid("");
        entity.update();
        setAttr("iCustomerInfo", entity);
        renderJson(suc());
    }

    // 查询主页页面信息
    public void queryMsg(){
        ObjectNode jsonNodes = service.queryMsg();
        renderJson(jsonNodes.toString());
//        return jsonNodes.toString();
    }

    public void close(){
        RestTemplate restTemplate = new RestTemplate();
       restTemplate.postForEntity("http://127.0.0.1:8080/closeed", null, null);
    }


    // 查询大屏页面信息
    public void queryWarnInfo(){
        ObjectNode jsonNodes = service.queryWarnInfo();
        renderJson(jsonNodes.toString());
//        return jsonNodes.toString();
    }

}
